<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$return=array();
$return['basic']=$this->plugin_setting('basic');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='main'){
	
	exi($return);
}
/*******op*******/
if($_RQ['op']=='list'){
	//查询进入该页面的客户所有订单
	$params=array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']);
	if(isset($_RQ['status']) && $_RQ['status'] != 10){
		$params['status']=intval($_RQ['status']);
		$return['status']=$_RQ['status'];
	}else{
		$return['status']=10;
	}
	$order_list=pdo_getall('jy_edu_order',$params,'','','createtime desc');
	if($order_list){
		foreach($order_list as &$item){
			$item=$this->model('order')->get_order($item['id']);			
		}
	}
	set_html('title','报名列表');
	$return['order_list']=$order_list;
	exi($return);
}
//订单详情
if($_RQ['op']=='detail'){
	$payid=intval($_RQ['payid']);
	$id=intval($_RQ['id']);
	if(!$id && !$payid){
		exi('订单不存在，请重新选择'.$id,'error');
	}
	if($id){
		$order=$this->model('order')->get_order($id);
	}elseif($payid){
		$id=pdo_getcolumn('jy_edu_order',array('uniacid'=>$_SESSION['uniacid'],'pay_id'=>$payid),'id');
		$order=$this->model('order')->get_order($id);
	}
	$return['member']=model('core/member')->detail($order['mid'],array('credit1','credit2','mobile','avatar','nickname'));
	$order['lesson']=pdo_get('jy_edu_lesson',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['lesson_id']));
	$return['order']=$order;
	set_html('title','报名详情');
	exi($return);
}
if($_RQ['op']=='receive'){
	if(!$_RQ['id']){
		exi('订单不存在，请重新选择订单','error');
	}
	pdo_update('jy_edu_order',array('status'=>'4'),array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	//确认订单后，计算员工佣金,存入佣金日志表，并更新员工表员工总佣金
	$worker_id=pdo_getcolumn('jy_edu_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']),'worker_id');
	$pay=pdo_getcolumn('jy_edu_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']),'pay');
	$lev_id=pdo_getcolumn('jy_edu_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$worker_id),'lev');
	$rate=pdo_getcolumn('jy_edu_lev',array('uniacid'=>$_SESSION['uniacid'],'id'=>$lev_id),'rate');
	$storeid=pdo_getcolumn('jy_edu_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']),'storeid');
	if($rate){
		$insert=array(
		'uniacid'=>$_SESSION['uniacid'],
		'worker_id'=>$worker_id,
		'order_id'=>$_RQ['id'],
		'money'=>$pay*$rate/100,
		'storeid'=>$storeid,
		'createtime'=>TIMESTAMP,
		);
		pdo_insert('jy_edu_commission_log',$insert);
		$commission=pdo_getcolumn('jy_edu_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$worker_id),'commission');
		$commission=$commission+$pay*$rate/100;
		pdo_update('jy_edu_worker',array('commission'=>$commission),array('uniacid'=>$_SESSION['uniacid'],'id'=>$worker_id));
	}
	
	exi('确认服务成功');
}
if($_RQ['op']=='del'){
	if(!$_RQ['id']){
		exi('订单不存在，请重新选择订单','error');
	}
	pdo_delete('jy_edu_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	exi('删除预约成功');
}
if($_RQ['op']=='pay'){
	$id=$_RQ['id'];
	if(!$id){
		exi('订单不存在，请重新选择订单','error');
	}
	$pay_id=pdo_getcolumn('jy_edu_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id),'pay_id');
	exi($pay_id);
}